package com.teamone.etl.systemsettings.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teamone.etl.systemsettings.dao.DepartmentDao;
import com.teamone.etl.systemsettings.entity.Department;
import com.teamone.etl.systemsettings.entity.Post;
import com.teamone.etl.systemsettings.service.DepartmentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * (Department)表服务实现类
 *
 * @author makejava
 * @since 2021-01-20 14:31:57
 */
@Service("departmentService")
@Transactional(rollbackFor = Exception.class)
public class DepartmentServiceImpl extends ServiceImpl<DepartmentDao, Department> implements DepartmentService {

    /**
     * 通过主键id进行单条数据查询
     *
     * @param id 主键id
     * @return 单条数据
     */
    @Override
    public Department selectOne(Integer id) {
        return baseMapper.selectOne(id);
    }

    /**
     * 添加部门
     *
     * @param department 前台传入信息
     * @return 对象 or    如果当前部门名称已经存在 return null
     */
    @Override
    public Boolean createDepartment(Department department) {
        //通过部门名称进行查询
        Department department1 = baseMapper.selectDepartmentByName(department.getName());
        //如果部门存在 !=null
        if(department1 != null) {
            //返回失败
            return false;
        }
        //不存在添加部门
        baseMapper.createDepartment(department);
        return true;
    }

    /**
     *
     * @param id 部门编号
     * @return
     */
    @Override
    public List<Post> selectCountPost(Integer id) {

        List<Post> postList = baseMapper.selectCountPost(id);
        return postList;


    }


}